/**
 * @ Author: luoqi
 * @ Create Time: 2024-07-26 23:57
 * @ Modified by: luoqi
 * @ Modified time: 2025-02-25 19:36
 * @ Description:
 */
#include <stdbool.h>
#include <stdint.h>
#include <bsp.h>
#include "cli.h"
#include "../qshell/qterm.h"


static uint8_t task_cli_stack[1024 * 2];
TX_THREAD task_cli;
void task_cli_hdl(uint32_t arg)
{
    UNUSED(arg);
    uint8_t buf[64] = {0};
    
    while(1) {
        int sz = bsp_uart1_recv(buf, sizeof(buf), TX_WAIT_FOREVER);
        for(int i = 0; i < sz; i++) {
            qterm_exec(buf[i]);
        }
    }
}

int cli_init(void)
{
    qterm_init();
    tx_thread_create(&task_cli, "cli", task_cli_hdl, 0,
        task_cli_stack, sizeof(task_cli_stack),
        20, 20, TX_NO_TIME_SLICE, TX_AUTO_START);
    return 0;
}
